function getUrlParam(key){
    var reg = new RegExp("(^|$)"+key+"=([^$]*)(&|$)");
    var name = window.location.search.substr(1).match(reg);
    if(name != null) return unescape(name[2]);return null;
};

var pageCommon = {
	showLoginWindow : function(){
		$('#showloginBtn').bind('click',function(){
			$("#window-loginSelect").removeClass("E03-none");
		});
		$('#window-loginSelect a.btn_close').bind('click',function(){
			$("#window-loginSelect").addClass("E03-none");
		});
	},
    bottomdata : function(){       
        var _n = $('.b_snews li').length;
        if(_n>3){
            $('.b_snews').vTicker({showItems:3});
        };
        $('.bottomdata,.bottomdata1,.bottomdata2').vTicker({showItems:1});
    },
    bottomnews : function(){
        $('.bottomnews').on('click','.min_btn',function(){
            $('.min_btn').hide();
            $('.max_btn').show();
            $('.bottomnews').animate({height:'50px'},300,function(){
                $(this).addClass('min');    
            });
            ga('send','event','index','Click','noticeclose');
        });
        $('.bottomnews').on('click','.max_btn',function(){
            $('.min_btn').show();
            $('.max_btn').hide();
            $('.bottomnews').removeClass('min');
            $('.bottomnews').animate({height:'100px'},300);
        });
    },
    menuSelected : function(){
        /*导航选中切换*/
        $('#menulist>li').removeClass("hover");
        $('#menu_' + $('#menulist').attr("attr-flag")).addClass("hover");
    },
    nocomplete : function(){
        $("form").attr("autocomplete","off");
        $("input[type='text']").attr("autocomplete","off");
        $("input[type='password']").attr("autocomplete","off");
        $("input[type='hidden']").attr("autocomplete","off");
        var splitinp = '<!-- 阻止表单自动填充用户名和密码的input --><input type="password" style="width:0px; height:0px; position:absolute; top:-99em; left:-99em; z-index:-2;" />';
        $("input#login-password:eq(0),input#password:eq(0),input#passwordfield:eq(0),input#partnerPassword:eq(0)").before(splitinp);
    },
    hideClientpop : function(){
        $("a.cs_close").click(function(){
            $("#CS-window").hide(300);
        });
    },
    navMtTips : function(){
        var o_txt = '';
        $('dd.maintain>a').hover(function(){
            o_txt = $(this).text();
            $(this).text('维护中...');
        },function(){
            $(this).text(o_txt);
        });
    },
    //针对头部登录的placeholder效果
     inpupTips : function(){
        $('input.login_inp').val('');
        $('em.nstips').bind('click',function(){
            $(this).prev('input').focus();
            $(this).hide();
        });
        $('input.login_inp').bind({
            keydown:function(){$(this).next('em.nstips').hide();},
            blur:function(){
                var thisVal = $(this).val();
                if(thisVal){
                    $(this).next('em.nstips').hide();
                }else{
                    $(this).next('em.nstips').show();
                };
            }
        });
        //以下全站相关提示语placeholder效果
        $('span.tips').bind('click',function(){
            $(this).prev('input').focus();
            $(this).hide();
        });
        $('input.txt_in').bind({
            keydown:function(){$(this).next('span.tips').hide();},
            blur:function(){
                var thisVal = $(this).val();
                if(thisVal){
                    $(this).next('span.tips').hide();
                }else{
                    $(this).next('span.tips').show();
                };
            }
        });
    },
    windowclosetrigger:function(){
        $("#window_callback a.dialog_close").trigger("click");
    },
    //给我回电(初始)
    showcallwindow:function(){     
        var hiddenValues = prj.getHiddenValues('#js-footer-local-hiddens');
        var globalsFormatPhone = hiddenValues.globalsFormatPhone;    
        var hv =  prj.getHiddenValues('#js-global-hiddens');
        var customerType = hv.customerType; 
         $("#callbackbtn").bind("click",function(){
            $.dialog({
                id:'window_callback',
                title:'给我回电',
                type:'jpop',
                html:'<div class="cont_call">\
                          <b>※ 请输入要回拨的号码，我们将在一分钟内向您致电。</b>\
                          <input class="callbaknum txt_in" id="callbacknumA" maxlength="12"/>\
                          <a class="btn_submit" id="btn_submitphone" href="javascript:;">确认提交</a>\
                      </div>'
            })
            if(customerType!=1){
                $("#callbacknumA").focus();
            }
            $("#callbacknumA").val(globalsFormatPhone); 
        })                  
    },
    //确认提交手机号码
    submitphonenumber:function(){
        $(document).on("click","#btn_submitphone",function(){
            var that = $(this);
            $.when(_ajax.submitcallphone(that)).done(function(data){
                //成功
                if(data.status == 1){     
                    pageCommon.windowclosetrigger();
                }else if(data.status == 0){
                    $.dialog({
                        html:data.mes
                    })
                }
            });
        })
    },
    commonfreeplay:function(){
        $("div.frplayWrap a.frplaybtn").click(function(){
            var gameid = $(this).data('idname');
            prj.popvisit('',gameid);
        })
    },
    //优惠中心 红包提示
    aboutBonusTips:function(){  
        var hiddenValues  = prj.getHiddenValues($('#js-global-hiddens'));  
        var _customertype = ''; 
        var static_content_prefix =''; 
        if(hiddenValues){
            _customertype         = hiddenValues.customerType; 
            static_content_prefix =  hiddenValues.static_content_prefix; 
            if(_customertype == '1'){
                var params = {action:"list"};
                //这里不需要loading，因为是只请求数据
                // prj.loading(static_content_prefix + '/_default/__static/__images/load-f1.gif');
                $.ajax({
                    type       : 'POST',
                    url        : 'myPromotionJson.htm',
                    data       : params,
                    success : function(res) {
                        // prj.loadingcancel();
                        //发送失败
                        if(res.status == 0){
                            return;
                        }else{
                            if(res.data){
                                for (var i = 0; i < res.data.length; i++) {
                                    var flag = res.data[i].recordFlag;
                                    var _length = $("#CS-window a.tipslink").length;
                                    if(flag == 1){
                                        var html='<a class="tipslink" href="firstDepositPromotion.htm">'+
                                            '<img src="'+static_content_prefix+'/_default/__static/__images/newcomm/bonustips.gif" />'+
                                            '</a>';
                                        if(_length == 0){
                                            $("#CS-window").append(html);
                                        }else{
                                            return
                                        }                                                                           
                                    }else{
                                        return;
                                    }
                                }
                            }
                        }          
                    },
                    error: function(res) {
                        prj.loadingcancel();
                        $.dialog({
                            html:'网络异常，请重试'
                        });
                    }
                });
            }
        }               
    },
    init : function(){
    	this.showLoginWindow();
        this.navMtTips();
        this.bottomnews();
        this.bottomdata();
        this.menuSelected();
        this.nocomplete();
        this.hideClientpop();
        this.inpupTips();
        this.showcallwindow();
        this.submitphonenumber();     
        this.commonfreeplay();  
        this.aboutBonusTips();
    }
};
//ajax
var _ajax={
    submitcallphone:function(controlBtn){
        var params = {phone:$('#callbacknumA').val()};
        var dfd = $.Deferred(); 
        tool.ajax({
            type    :'post',
            url     :'customerCallReturn.htm',
            data    :params,
            controlBtn : controlBtn,
            success:function(data){
                var result = data;
                dfd.resolve(result);
            },
            error:function(){
                $.dialog({
                   html : '出现一些未知异常，请重试' 
                })
            }
        });
        return dfd.promise();
    }
}
$(function(){
    pageCommon.init();
});



/*
* vertical news ticker
* Tadas Juozapaitis ( kasp3rito@gmail.com )
* http://www.jugbit.com/jquery-vticker-vertical-news-ticker/
* v 1.4
*/
(function ($) {
    $.fn.vTicker = function (options) {
        var defaults = {
            speed: 700,
            pause: 4000,
            showItems: 3,
            animation: '',
            mousePause: true,
            isPaused: false,
            direction: 'up',
            height: 0
        };

        var options = $.extend(defaults, options);

        moveUp = function (obj2, height, options) {
            if (options.isPaused)
                return;

            var obj = obj2.children('ul');

            var clone = obj.children('li:first').clone(true);

            if (options.height > 0) {
                height = obj.children('li:first').height();
            }

            obj.animate({ top: '-=' + height + 'px' }, options.speed, function () {
                $(this).children('li:first').remove();
                $(this).css('top', '0px');
            });

            if (options.animation == 'fade') {
                obj.children('li:first').fadeOut(options.speed);
                if (options.height == 0) {
                    obj.children('li:eq(' + options.showItems + ')').hide().fadeIn(options.speed).show();
                }
            }

            clone.appendTo(obj);
        };

        moveDown = function (obj2, height, options) {
            if (options.isPaused)
                return;

            var obj = obj2.children('ul');

            var clone = obj.children('li:last').clone(true);

            if (options.height > 0) {
                height = obj.children('li:first').height();
            }

            obj.css('top', '-' + height + 'px')
            .prepend(clone);

            obj.animate({ top: 0 }, options.speed, function () {
                $(this).children('li:last').remove();
            });

            if (options.animation == 'fade') {
                if (options.height == 0) {
                    obj.children('li:eq(' + options.showItems + ')').fadeOut(options.speed);
                }
                obj.children('li:first').hide().fadeIn(options.speed).show();
            }
        };

        return this.each(function () {
            var obj = $(this);
            var maxHeight = 0;

            obj.css({ overflow: 'hidden', position: 'relative' })
            .children('ul').css({ position: 'absolute', margin: 0, padding: 0 })
            .children('li').css({ margin: 0, padding: 0 });

            if (options.height == 0) {
                obj.children('ul').children('li').each(function () {
                    if ($(this).height() > maxHeight) {
                        maxHeight = $(this).height();
                    }
                });

                obj.children('ul').children('li').each(function () {
                    $(this).height(maxHeight);
                });

                obj.height(maxHeight * options.showItems);
            }
            else {
                obj.height(options.height);
            }

            var interval = setInterval(function () {
                if (options.direction == 'up') {
                    moveUp(obj, maxHeight, options);
                }
                else {
                    moveDown(obj, maxHeight, options);
                }
            }, options.pause);

            if (options.mousePause) {
                obj.bind("mouseenter", function () {
                    options.isPaused = true;
                }).bind("mouseleave", function () {
                    options.isPaused = false;
                });
            }
        });
    };
})(jQuery);